import json
from collections import defaultdict
from datetime import datetime

import httpx
import requests
from flask import request, jsonify
from flask_restx import Namespace, Resource, fields
from flask_jwt_extended import jwt_required
from sqlalchemy import and_
from requests.cookies import RequestsCookieJar
import app1

# 导入 tb_alarm 模型
from app1 import db
from app1 import api

from app1.customdate import CustomDate
from app1.utils import format_response

# 创建 Flask-RESTx 命名空间
ns_sjfxpt = Namespace('ns_sjfxpt', description='数据分析平台')

Sjfxpt_post_login_model = ns_sjfxpt.model(
    'sjfxpt_post_login',
    {
        'user_id': fields.String(description='用户id', required=True, default=""),
        'user_pwd': fields.String(description='用户密码', required=True, default="")
    }
)

# 定义 Flask-RESTx 模型
Sjfxpt_login_model = ns_sjfxpt.model('Sjfxpt_login', {
    'login_cookie': fields.String(description='登录cookie'),
    'login_id': fields.String(description='登录id'),
})

# 定义外层的响应模型
response_sjfxpt_login_model = ns_sjfxpt.model('Response_Sjfxpt_login', {
    'message': fields.Nested(ns_sjfxpt.model('Message_Sjfxpt_login', {
        "result": fields.Integer(description='查询结果返回值'),
        "result_text": fields.String(description='查询结果信息'),
        'count': fields.Integer(description='查询结果返回数据条数'),
        'data': fields.List(fields.Nested(Sjfxpt_login_model))
    }))
})

# get login
Sjfxpt_post_getlogin_model = ns_sjfxpt.model(
    'sjfxpt_post_getlogin',
    {
        'login_cookie': fields.String(description='登录cookie'),
    }
)

# 定义 Flask-RESTx 模型
Sjfxpt_getlogin_model = ns_sjfxpt.model('Sjfxpt_login', {
    'login_cookie': fields.String(description='登录cookie'),
    'login_id': fields.String(description='登录id'),
})

# 定义外层的响应模型
response_sjfxpt_getlogin_model = ns_sjfxpt.model('Response_Sjfxpt_login', {
    'message': fields.Nested(ns_sjfxpt.model('Message_Sjfxpt_login', {
        "result": fields.Integer(description='查询结果返回值'),
        "result_text": fields.String(description='查询结果信息'),
        'count': fields.Integer(description='查询结果返回数据条数'),
        'data': fields.List(fields.Nested(Sjfxpt_getlogin_model))
    }))
})

# sys: C-AMLAmeiy
# classify: txnChannel
# stime: 2024-10-22 20:00
# etime: 2024-10-23 23:59

# get top10
Sjfxpt_post_top10_model = ns_sjfxpt.model(
    'sjfxpt_post_top10',
    {
        'sys': fields.String(description='系统名', default="C-AMLA"),
        'classify': fields.String(description='查询类别', default="txnChannel"),
        'stime': fields.String(description='开始时间',
                               default=str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))),
        'etime': fields.String(description='结束时间', default=str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))),
    }
)

# 定义 Flask-RESTx 模型
Sjfxpt_gettop10_model = ns_sjfxpt.model('Sjfxpt_gettop10', {
    "top10": fields.List(fields.Raw),  # 不固定格式
})

# 定义外层的响应模型
response_sjfxpt_gettop10_model = ns_sjfxpt.model('Response_Sjfxpt_gettop10', {
    'message': fields.Nested(ns_sjfxpt.model('Message_Sjfxpt_gettop10', {
        "result": fields.Integer(description='查询结果返回值'),
        "result_text": fields.String(description='查询结果信息'),
        'count': fields.Integer(description='查询结果返回数据条数'),
        'data': fields.Nested(Sjfxpt_gettop10_model)
    }))
})


# # 获取 cookie
# @ns_sjfxpt.route('/user/dologin_ldap')
# class Sjfx_login_MapResource(Resource):
#     @ns_sjfxpt.expect(Sjfxpt_post_login_model)
#     # @jwt_required()
#     @ns_sjfxpt.marshal_with(response_sjfxpt_login_model)
#     def post(self):
#         try:
#             """多条件查询工单列表 日期格式：2024-06-18 18:10:13"""  # 接口说明紧跟在函数后面
#             sjfx_data = api.payload
#
#             # 拼接 url
#             baseurl = (app1.app.config['SJFXPT']) + "user/dologin_ldap"
#
#             # 构造请求头
#             headers = {
#                 "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
#             }
#
#             # x-www-form-urlencoded
#             payload = {
#                 "user_id": sjfx_data['user_id'],
#                 "user_pwd": sjfx_data['user_pwd']
#             }
#
#             req = requests
#
#             # 发送POST请求
#             response = req.post(baseurl, headers=headers, data=payload)
#
#             print(response.request.headers)
#             print(response.headers)
#             print(response.cookies)
#
#             s = req.session()
#             print("debug1")
#             print(s.cookies.get_dict)
#
#             # 判断请求是否成功
#             if response.status_code == 200:
#                 # 获取响应数据，假设 cookie 在响应头里，user_id 在响应体中
#                 # login_cookie = response.cookies.get_dict()  # 获取cookie
#                 login_cookie = requests.utils.dict_from_cookiejar(response.cookies)
#                 # login_id = response.json().get('user_id')  # 获取响应中的 user_id
#                 login_id = sjfx_data['user_id']
#
#                 # =======================================================================
#                 print("debug9")
#                 # 拼接 url
#                 baseurl = (app1.app.config['SJFXPT']) + "user/getLogin"
#                 print(baseurl)
#
#                 jar_cookies = requests.utils.cookiejar_from_dict(login_cookie)
#                 print(jar_cookies)
#                 print("debug3")
#
#                 # 构造请求头
#                 headers = {
#                     # "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
#                     # "Content-Type": "text/html;charset=UTF-8",
#                     # "Cookie": sjfx_data['login_cookie'],
#                     "Cookie": "JSESSIONID=" + login_cookie['JSESSIONID'],
#                     # "Origin": "http://22.122.49.143:81",
#                     # "Host": "22.122.49.143:81"
#                 }
#
#                 # jar_cookies = requests.utils.cookiejar_from_dict(ck_dict)
#                 # print(jar_cookies)
#                 # print("debug3")
#                 cookie_jar = RequestsCookieJar()
#                 cookie_jar.update(jar_cookies)
#
#                 # req = requests
#
#                 # s = req.session()
#                 # s.cookies.set("Cookie",jar_cookies)
#                 s.cookies.update(jar_cookies)
#                 print(s.cookies.get_dict)
#                 print(response.cookies)
#
#                 # response = requests.get(baseurl, headers=headers)
#                 # response = req.get(baseurl, headers=headers, cookies=cookie_jar)
#                 response = req.get(baseurl, headers=headers, cookies=response.cookies)
#                 print(response.request.headers)
#                 print("debug11")
#                 print(response.headers)
#                 print("debug12")
#                 print(response.cookies)
#                 print("debug13")
#                 print(response.text.strip())
#
#                 # ======================================================================+
#
#                 # 准备返回的数据
#                 response_data = {
#                     "message": {
#                         "result": 1,  # 查询成功
#                         "result_text": "登录成功",
#                         "count": 1,
#                         "data": [
#                             {
#                                 "login_cookie": login_cookie,  # 返回 cookie
#                                 "login_id": login_id  # 返回 user_id
#                             }
#                         ]
#                     }
#                 }
#
#                 # 返回封装好的响应模型，状态码200
#                 return response_data, 200
#
#             else:
#                 # 如果请求失败，准备失败的响应数据
#                 response_data = {
#                     "message": {
#                         "result": 0,  # 查询失败
#                         "result_text": f"登录失败: {response.status_code}",
#                         "count": 0,
#                         "data": []
#                     }
#                 }
#
#                 # 返回封装好的失败响应模型，状态码400
#                 return response_data, 400
#
#         except Exception as e:
#             # 捕获异常并准备异常响应数据
#             response_data = {
#                 "message": {
#                     "result": 0,  # 查询异常
#                     "result_text": f"查询异常: {str(e)}",
#                     "count": 0,
#                     "data": []
#                 }
#             }
#
#             # 返回封装好的异常响应模型，状态码201
#             return response_data, 201

# # 获取 cookie
# @ns_sjfxpt.route('/user/dologin_ldap')
# class Sjfx_login_MapResource(Resource):
#     @ns_sjfxpt.expect(Sjfxpt_post_login_model)
#     @ns_sjfxpt.marshal_with(response_sjfxpt_login_model)
#     async def post(self):
#         try:
#             sjfx_data = api.payload
#             baseurl = app1.app.config['SJFXPT'] + "user/dologin_ldap"
#
#             headers = {
#                 "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
#             }
#
#             payload = {
#                 "user_id": sjfx_data['user_id'],
#                 "user_pwd": sjfx_data['user_pwd']
#             }
#
#             async with httpx.AsyncClient() as client:
#                 response = await client.post(baseurl, headers=headers, data=payload)
#
#                 if response.status_code == 200:
#                     login_cookie = response.cookies
#                     login_id = sjfx_data['user_id']
#
#                     # 获取 login_id
#                     baseurl = app1.app.config['SJFXPT'] + "user/getLogin"
#                     headers["Cookie"] = f"JSESSIONID={login_cookie['JSESSIONID']}"
#
#                     response = await client.get(baseurl, headers=headers)
#
#                     # 准备返回的数据
#                     response_data = {
#                         "message": {
#                             "result": 1,
#                             "result_text": "登录成功",
#                             "count": 1,
#                             "data": [
#                                 {
#                                     "login_cookie": dict(login_cookie),  # 返回 cookie
#                                     "login_id": login_id
#                                 }
#                             ]
#                         }
#                     }
#
#                     return response_data, 200
#                 else:
#                     response_data = {
#                         "message": {
#                             "result": 0,
#                             "result_text": f"登录失败: {response.status_code}",
#                             "count": 0,
#                             "data": []
#                         }
#                     }
#
#                     return response_data, 400
#         except Exception as e:
#             return {"message": {"result": 0, "result_text": str(e), "count": 0, "data": []}}, 500

# 获取 cookie
@ns_sjfxpt.route('/user/dologin_ldap')
class Sjfx_login_MapResource(Resource):
    @ns_sjfxpt.expect(Sjfxpt_post_login_model)
    @ns_sjfxpt.marshal_with(response_sjfxpt_login_model)
    def post(self):
        try:
            sjfx_data = api.payload
            baseurl = app1.app.config['SJFXPT'] + "user/dologin_ldap"

            headers = {
                "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
            }

            payload = {
                "user_id": sjfx_data['user_id'],
                "user_pwd": sjfx_data['user_pwd']
            }

            # 使用同步客户端
            with httpx.Client() as client:
                response = client.post(baseurl, headers=headers, data=payload)

                if response.status_code == 200:
                    login_cookie = response.cookies
                    login_id = sjfx_data['user_id']

                    # 获取 login_id
                    baseurl = app1.app.config['SJFXPT'] + "user/getLogin"
                    headers["Cookie"] = f"JSESSIONID={login_cookie['JSESSIONID']}"

                    response = client.get(baseurl, headers=headers)

                    # 准备返回的数据
                    response_data = {
                        "message": {
                            "result": 1,
                            "result_text": "登录成功",
                            "count": 1,
                            "data": [
                                {
                                    "login_cookie": dict(login_cookie),  # 返回 cookie
                                    "login_id": login_id
                                }
                            ]
                        }
                    }

                    return response_data, 200
                else:
                    response_data = {
                        "message": {
                            "result": 0,
                            "result_text": f"登录失败: {response.status_code}",
                            "count": 0,
                            "data": []
                        }
                    }

                    return response_data, 400
        except Exception as e:
            return {"message": {"result": 0, "result_text": str(e), "count": 0, "data": []}}, 500


# 获取 登录用户
@ns_sjfxpt.route('/user/getLogin')
class Sjfx_getlogin_MapResource(Resource):
    @ns_sjfxpt.expect(Sjfxpt_post_getlogin_model)
    # @jwt_required()
    @ns_sjfxpt.marshal_with(response_sjfxpt_getlogin_model)
    def post(self):
        try:
            """多条件查询工单列表 日期格式：2024-06-18 18:10:13"""  # 接口说明紧跟在函数后面
            sjfx_data = api.payload
            print(sjfx_data)
            print(sjfx_data['login_cookie'])
            print(type(sjfx_data['login_cookie']))

            print("debug1")
            str_cookie = sjfx_data['login_cookie'].replace("'", '"')
            print(str_cookie)
            print("debug4")
            ck_dict = json.loads(str_cookie)
            print(ck_dict)
            print(ck_dict['JSESSIONID'])
            print("debug2")

            # 拼接 url
            baseurl = (app1.app.config['SJFXPT']) + "user/getLogin"
            print(baseurl)

            jar_cookies = requests.utils.cookiejar_from_dict(ck_dict)
            print(jar_cookies)
            print("debug3")

            # 构造请求头
            headers = {
                # "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
                # "Content-Type": "text/html;charset=UTF-8",
                # "Cookie": sjfx_data['login_cookie'],
                "Cookie": "JSESSIONID=" + ck_dict['JSESSIONID'],
                # "Origin": "http://22.122.49.143:81",
                # "Host": "22.122.49.143:81"
            }

            # jar_cookies = requests.utils.cookiejar_from_dict(ck_dict)
            # print(jar_cookies)
            # print("debug3")
            cookie_jar = RequestsCookieJar()
            cookie_jar.update(jar_cookies)

            req = requests

            s = req.session()
            s.cookies.set("Cookie", jar_cookies)
            print(s.cookies.get_dict)

            # response = requests.get(baseurl, headers=headers)
            response = req.get(baseurl, headers=headers, cookies=cookie_jar)
            print(response.request.headers)
            print(response.headers)
            print(response.cookies)

            # print(response.json())

            if response.status_code == 200:
                # 直接获取返回的文本作为 login_id
                login_id = response.text.strip()
                print(login_id)

                response_data = {
                    "message": {
                        "result": 1,
                        "result_text": "查询成功",
                        "count": 1,
                        "data": [
                            {
                                # "login_cookie": sjfx_data['login_cookie'],
                                "login_cookie": response.cookies.get_dict(),
                                "login_id": login_id  # 使用返回的7位字符串
                            }
                        ]
                    }
                }
                return response_data, 200
            else:
                response_data = {
                    "message": {
                        "result": 0,
                        "result_text": f"查询失败: {response.status_code}",
                        "count": 0,
                        "data": []
                    }
                }
                return response_data, 400

        except Exception as e:
            # 捕获异常并准备异常响应数据
            response_data = {
                "message": {
                    "result": 0,  # 查询异常
                    "result_text": f"查询异常: {str(e)}",
                    "count": 0,
                    "data": []
                }
            }

            # 返回封装好的异常响应模型，状态码201
            return response_data, 201


# 获取 交易量
@ns_sjfxpt.route('/app/top10')
class Sjfx_gettop10_MapResource(Resource):
    @ns_sjfxpt.expect(Sjfxpt_post_top10_model)
    # @jwt_required()
    @ns_sjfxpt.marshal_with(response_sjfxpt_gettop10_model)
    def post(self):
        """根据给定的应用和交易类型查询交易量"""
        try:
            sjfx_data = api.payload

            # 拼接 url
            baseurl = (app1.app.config['SJFXPT']) + "app/top10"
            print(baseurl)

            # 构造请求头
            headers = {
                "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
            }
            print(headers)

            # 'sys': fields.String(description='系统名'),
            # 'classify': fields.String(description='查询类别'),
            # 'stime': fields.String(description='开始时间',
            #                        default=str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))),
            # 'etime': fields.String(description='结束时间', default=str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))),
            # x-www-form-urlencoded

            payload = {
                "sys": sjfx_data['sys'],
                "classify": sjfx_data['classify'],
                "stime": sjfx_data['stime'],
                "etime": sjfx_data['etime']
            }
            print(payload)

            print("debug1")

            # test999
            # {
            #     "sys": "C-AMLA",
            #     "classify": "txnChannel",
            #     "stime": "2024-10-23 20:00:00",
            #     "etime": "2024-10-24 23:59:00"
            # }

            if sjfx_data['sys'] == "test999":
                top10json = {
                    "top10": [
                        {
                            "appName": "C-AMLA",
                            "classify": "e6",
                            "cname": "e6",
                            "txnVol": 273135,
                            "txnRatioSuc": 0,
                            "txnRespTime": 667,
                            "pollTime": "10-23 08:00"
                        },
                        {
                            "appName": "C-AMLA",
                            "classify": "e5",
                            "cname": "e5",
                            "txnVol": 258542,
                            "txnRatioSuc": 0,
                            "txnRespTime": 618,
                            "pollTime": "10-23 08:00"
                        }
                    ]
                }

                # 准备返回的数据
                response_data = {
                    "message": {
                        "result": 2,  # 查询成功
                        "result_text": "测试获取成功",
                        "count": len(top10json["top10"]),
                        "data": top10json
                    }
                }

                return response_data, 202

            # 发送POST请求
            response = requests.post(baseurl, headers=headers, data=payload)
            # 判断请求是否成功
            if response.status_code == 200:
                top10data = response.text.split('|')

                print(response.text)
                print(top10data[1])
                print(type(top10data[1]))
                print(json.loads(top10data[1]))
                top10json = {"top10": json.loads(top10data[1])}

                # 准备返回的数据
                response_data = {
                    "message": {
                        "result": 1,  # 查询成功
                        "result_text": sjfx_data['sys'] + " 获取成功",
                        "count": len(top10json["top10"]),
                        "data": top10json
                    }
                }

                return response_data, 200
            else:
                # 准备返回的数据
                response_data = {
                    "message": {
                        "result": 0,  # 查询成功
                        "result_text": sjfx_data['sys'] + " 获取失败",
                        "count": 0,
                        "data": {}
                    }
                }

                return response_data, 200

        except Exception as e:
            # 捕获异常并准备异常响应数据
            response_data = {
                "message": {
                    "result": 0,  # 查询异常
                    "result_text": f"查询异常: {str(e)}",
                    "count": 0,
                    "data": []
                }
            }

            # 返回封装好的异常响应模型，状态码201
            return response_data, 201

# import json
# from collections import defaultdict
# from datetime import datetime
#
# import requests
# from flask import request, jsonify
# from flask_restx import Namespace, Resource, fields
# from flask_jwt_extended import jwt_required
# from requests.cookies import RequestsCookieJar
# from sqlalchemy import and_
#
# import app1
#
# # 导入 tb_alarm 模型
# from app1 import db
# from app1 import api
#
# from app1.customdate import CustomDate
# from app1.utils import format_response
#
# # 创建 Flask-RESTx 命名空间
# ns_sjfxpt = Namespace('ns_sjfxpt', description='数据分析平台')
#
# Sjfxpt_post_login_model = ns_sjfxpt.model(
#     'sjfxpt_post_login',
#     {
#         'user_id': fields.String(description='用户id', required=True, default=""),
#         'user_pwd': fields.String(description='用户密码', required=True, default="")
#     }
# )
#
# # 定义 Flask-RESTx 模型
# Sjfxpt_login_model = ns_sjfxpt.model('Sjfxpt_login', {
#     'login_cookie': fields.String(description='登录cookie'),
#     'login_id': fields.String(description='登录id'),
# })
#
# # 定义外层的响应模型
# response_sjfxpt_login_model = ns_sjfxpt.model('Response_Sjfxpt_login', {
#     'message': fields.Nested(ns_sjfxpt.model('Message_Sjfxpt_login', {
#         "result": fields.Integer(description='查询结果返回值'),
#         "result_text": fields.String(description='查询结果信息'),
#         'count': fields.Integer(description='查询结果返回数据条数'),
#         'data': fields.List(fields.Nested(Sjfxpt_login_model))
#     }))
# })
#
# # get login
# Sjfxpt_post_getlogin_model = ns_sjfxpt.model(
#     'sjfxpt_post_getlogin',
#     {
#         'login_cookie': fields.String(description='登录cookie'),
#     }
# )
#
# # 定义 Flask-RESTx 模型
# Sjfxpt_getlogin_model = ns_sjfxpt.model('Sjfxpt_login', {
#     'login_cookie': fields.String(description='登录cookie'),
#     'login_id': fields.String(description='登录id'),
# })
#
# # 定义外层的响应模型
# response_sjfxpt_getlogin_model = ns_sjfxpt.model('Response_Sjfxpt_login', {
#     'message': fields.Nested(ns_sjfxpt.model('Message_Sjfxpt_login', {
#         "result": fields.Integer(description='查询结果返回值'),
#         "result_text": fields.String(description='查询结果信息'),
#         'count': fields.Integer(description='查询结果返回数据条数'),
#         'data': fields.List(fields.Nested(Sjfxpt_getlogin_model))
#     }))
# })
#
#
# # 获取 cookie
# @ns_sjfxpt.route('/user/dologin_ldap')
# class Sjfx_login_MapResource(Resource):
#     @ns_sjfxpt.expect(Sjfxpt_post_login_model)
#     # @jwt_required()
#     @ns_sjfxpt.marshal_with(response_sjfxpt_login_model)
#     def post(self):
#         try:
#             """多条件查询工单列表 日期格式：2024-06-18 18:10:13"""  # 接口说明紧跟在函数后面
#             sjfx_data = api.payload
#
#             # 拼接 url
#             baseurl = (app1.app.config['SJFXPT']) + "user/dologin_ldap"
#
#             # 构造请求头
#             headers = {
#                 "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
#             }
#
#             # x-www-form-urlencoded
#             payload = {
#                 "user_id": sjfx_data['user_id'],
#                 "user_pwd": sjfx_data['user_pwd']
#             }
#
#             # 发送POST请求
#             response = requests.post(baseurl, headers=headers, data=payload)
#
#             # 判断请求是否成功
#             if response.status_code == 200:
#                 # 获取响应数据，假设 cookie 在响应头里，user_id 在响应体中
#                 login_cookie = response.cookies.get_dict()  # 获取cookie
#                 # login_id = response.json().get('user_id')  # 获取响应中的 user_id
#                 login_id = sjfx_data['user_id']
#
#                 # 准备返回的数据
#                 response_data = {
#                     "message": {
#                         "result": 1,  # 查询成功
#                         "result_text": "登录成功",
#                         "count": 1,
#                         "data": [
#                             {
#                                 "login_cookie": login_cookie,  # 返回 cookie
#                                 "login_id": login_id  # 返回 user_id
#                             }
#                         ]
#                     }
#                 }
#
#                 # 返回封装好的响应模型，状态码200
#                 return response_data, 200
#
#             else:
#                 # 如果请求失败，准备失败的响应数据
#                 response_data = {
#                     "message": {
#                         "result": 0,  # 查询失败
#                         "result_text": f"登录失败: {response.status_code}",
#                         "count": 0,
#                         "data": []
#                     }
#                 }
#
#                 # 返回封装好的失败响应模型，状态码400
#                 return response_data, 400
#
#         except Exception as e:
#             # 捕获异常并准备异常响应数据
#             response_data = {
#                 "message": {
#                     "result": 0,  # 查询异常
#                     "result_text": f"查询异常: {str(e)}",
#                     "count": 0,
#                     "data": []
#                 }
#             }
#
#             # 返回封装好的异常响应模型，状态码201
#             return response_data, 201
#
#
# # 获取 登录用户
# @ns_sjfxpt.route('/user/getLogin')
# class Sjfx_getlogin_MapResource(Resource):
#     @ns_sjfxpt.expect(Sjfxpt_post_getlogin_model)
#     # @jwt_required()
#     @ns_sjfxpt.marshal_with(response_sjfxpt_getlogin_model)
#     def post(self):
#         try:
#             """多条件查询工单列表 日期格式：2024-06-18 18:10:13"""  # 接口说明紧跟在函数后面
#             sjfx_data = api.payload
#
#             data_dict = json.loads(sjfx_data['login_cookie'])
#
#             # 拼接 url
#             baseurl = (app1.app.config['SJFXPT']) + "user/getLogin"
#
#             # 构造请求头
#             headers = {
#                 # "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
#                 "Cookie": sjfx_data['login_cookie']
#             }
#
#             cookie_jar = RequestsCookieJar()  # 创建一个 cookie jar 对象
#             cookie_jar.update(sjfx_data['login_cookie'])
#
#             # response = requests.get(baseurl, headers=headers)
#             response = requests.get(baseurl, cookies=cookie_jar)
#
#             if response.status_code == 200:
#                 # 直接获取返回的文本作为 login_id
#                 login_id = response.text.strip()
#
#                 response_data = {
#                     "message": {
#                         "result": 1,
#                         "result_text": "查询成功",
#                         "count": 1,
#                         "data": [
#                             {
#                                 "login_cookie": sjfx_data['login_cookie'],
#                                 "login_id": login_id  # 使用返回的7位字符串
#                             }
#                         ]
#                     }
#                 }
#                 return response_data, 200
#             else:
#                 response_data = {
#                     "message": {
#                         "result": 0,
#                         "result_text": f"查询失败: {response.status_code}",
#                         "count": 0,
#                         "data": []
#                     }
#                 }
#                 return response_data, 400
#
#         except Exception as e:
#             # 捕获异常并准备异常响应数据
#             response_data = {
#                 "message": {
#                     "result": 0,  # 查询异常
#                     "result_text": f"查询异常: {str(e)}",
#                     "count": 0,
#                     "data": []
#                 }
#             }
#
#             # 返回封装好的异常响应模型，状态码201
#             return response_data, 201
#
#
# # 获取 交易量
# @ns_sjfxpt.route('/app/top10')
# class Sjfx_gettop10_MapResource(Resource):
#     @ns_sjfxpt.expect(Sjfxpt_post_login_model)
#     # @jwt_required()
#     @ns_sjfxpt.marshal_with(response_sjfxpt_login_model)
#     def post(self):
#         try:
#             """多条件查询工单列表 日期格式：2024-06-18 18:10:13"""  # 接口说明紧跟在函数后面
#             sjfx_data = api.payload
#
#         except Exception as e:
#             # 捕获异常并准备异常响应数据
#             response_data = {
#                 "message": {
#                     "result": 0,  # 查询异常
#                     "result_text": f"查询异常: {str(e)}",
#                     "count": 0,
#                     "data": []
#                 }
#             }
#
#             # 返回封装好的异常响应模型，状态码201
#             return response_data, 201
